package com.threeti.mecool.mobile.interfaces.assembler;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.dozer.Mapper;
import org.springframework.util.CollectionUtils;

import com.threeti.mecool.core.domain.model.Communication;
import com.threeti.mecool.core.domain.model.Memo;
import com.threeti.mecool.core.domain.model.acl.User;
import com.threeti.mecool.core.domain.model.basicdata.biz.ChannelSync;
import com.threeti.mecool.framework.util.Lists;
import com.threeti.mecool.mobile.interfaces.dto.ChannelDto;
import com.threeti.mecool.mobile.interfaces.dto.CommunicationDto;
import com.threeti.mecool.mobile.interfaces.dto.MemoDto;
import com.threeti.mecool.mobile.interfaces.dto.UserDto;
import com.threeti.mecool.mobile.util.DozerMapperSingleton;

public abstract class UserAssembler {
  public static UserDto toDto(User user) {
    Mapper transfer = DozerMapperSingleton.getInstance();
    UserDto destDto = new UserDto();
    transfer.map(user, destDto);
    return destDto;
  }
  
  public static CommunicationDto toDto(Communication srcDom) {
    Mapper transfer = DozerMapperSingleton.getInstance();
    CommunicationDto destDto = new CommunicationDto();
    transfer.map(srcDom, destDto);
    return destDto;
  }
  
  public static Communication toDom(CommunicationDto srcDto) {
    Mapper transfer = DozerMapperSingleton.getInstance();
    Communication destDom = new Communication();
    transfer.map(srcDto, destDom);
    return destDom;
  }
  
  public static List<CommunicationDto> toDtoList(List<Communication> srcDoms) {
    List<CommunicationDto> dtos = Lists.newArrayList();
    if(!CollectionUtils.isEmpty(srcDoms)){
      for(Communication comm : srcDoms){
        dtos.add(toDto(comm));
      }
    }
    return dtos;
  }
  
  public static ChannelDto toDto(ChannelSync srcDom) {
    Mapper transfer = DozerMapperSingleton.getInstance();
    ChannelDto destDto = new ChannelDto();
    transfer.map(srcDom, destDto);
    return destDto;
  }
  
  public static Set<ChannelDto> toDtoList(Set<ChannelSync> srcDoms) {
    Set<ChannelDto> dtos = new LinkedHashSet<ChannelDto>();
    if(!CollectionUtils.isEmpty(srcDoms)){
      for(ChannelSync channel : srcDoms){
        dtos.add(toDto(channel));
      }
    }
    return dtos;
  }
  
  public static MemoDto toDto(Memo srcDom) {
    Mapper transfer = DozerMapperSingleton.getInstance();
    MemoDto destDto = new MemoDto();
    transfer.map(srcDom, destDto);
    return destDto;
  }
  
  public static Memo toDom(MemoDto srcDto) {
    Mapper transfer = DozerMapperSingleton.getInstance();
    Memo destDom = new Memo();
    transfer.map(srcDto, destDom);
    return destDom;
  }
  
  public static List<MemoDto> toDtoList1(List<Memo> srcDoms) {
    List<MemoDto> dtos = Lists.newArrayList();
    if(!CollectionUtils.isEmpty(srcDoms)){
      for(Memo memo : srcDoms){
        dtos.add(toDto(memo));
      }
    }
    return dtos;
  }
}
